package com.dzx.permissionmanagersystem.controller;

import com.dzx.permissionmanagersystem.common.JsonData;
import com.dzx.permissionmanagersystem.dto.DeptLevelDto;
import com.dzx.permissionmanagersystem.param.DeptParam;
import com.dzx.permissionmanagersystem.service.SysDeptService;
import com.dzx.permissionmanagersystem.service.SysTreeService;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.LinkedHashSet;
import java.util.List;

/**
 * @author DuanZhaoXu
 * @ClassName:
 * @Description:
 * @date 2018年11月29日 14:00:02
 */
@Controller
@RequestMapping("/sys/dept")
@Slf4j
public class SysDeptController {


    @Resource
    private SysDeptService sysDeptService;

    @Resource
    private SysTreeService sysTreeService;


    @RequestMapping("/page.json")
    public ModelAndView page(){
        return  new ModelAndView("dept");
    }



    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveDept(DeptParam param) {
        sysDeptService.save(param);
        return JsonData.success();
    }


    @RequestMapping("/tree.json")
    @ResponseBody
    public JsonData tree() {
        List<DeptLevelDto> dtoList = sysTreeService.deptTree();
        return JsonData.success(dtoList);
    }


    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData updateDept(DeptParam param) {
        sysDeptService.update(param);
        return JsonData.success();
    }

    public static void  main(String[] args){
        LinkedHashSet<String> set = Sets.newLinkedHashSet();
        set.add("a");
        set.add("b");
        String  result =  set.iterator().next();
        System.out.println(result);
    }

}
